Skip to content

fix(metrics): raise SchemaValidationError for >8 metric dimensions #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

heitorlessa
Copy link
Contributor

Issue number: #1239

Summary

Changes

Please provide a summary of what's being changed

Lambda Powertools adds a service CloudWatch Metric Dimension on top of user-defined dimensions. If customers add 9 user-defined dimensions, Powertools were previously adding service dimension directly into the dictionary making EMF to not process these metrics - EMF is an async process managed by CloudWatch Logs and it fails silently, all validation must happen on the client side for any feedback.

This PR addresses our documentation stating that the limit is 8 and ensures our service dimension addition goes through the same user-defined dimension validation process.

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 7, 2022
@github-actions github-actions bot added the bug Something isn't working label Jun 7, 2022
@pull-request-size pull-request-size bot removed the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 7, 2022
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jun 7, 2022
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 7, 2022
@heitorlessa heitorlessa requested a review from am29d June 7, 2022 12:59
@heitorlessa
Copy link
Contributor Author

@am29d @dnlopes could either of you have a second look before we release it?

@dnlopes
Copy link

dnlopes commented Jun 7, 2022

I was wondering if this is not a breaking change. If EMF fails silently, we might have customers sending more than the allowed dimensions in theirs runtime (but failing silently). As soon as they bump the powertools version, their code will start to blowup at runtime instead of just not producing metrics dimensions.

@@ -178,7 +178,7 @@ def serialize_metric_set(
metadata = self.metadata_set

if self.service and not self.dimension_set.get("service"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specific from this PR, but won't the condition not self.dimension_set.get("service") blow up if the key is not present? Shouldn't it be something like not self.dimension_set.get("service", "")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because .get will return None as the default sentinel value, hence why it's suitable within the if condition here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, and self.dimension_set.get("service") is not None would also work here ;-)

>>> a = {}
>>> not a.get("blah")
True
>>> a.get("blah") is None
True

@heitorlessa
Copy link
Contributor Author

I was wondering if this is not a breaking change. If EMF fails silently, we might have customers sending more than the allowed dimensions in theirs runtime (but failing silently). As soon as they bump the powertools version, their code will start to blowup at runtime instead of just not producing metrics dimensions.

My personal take is that this falls under a bug - we should've been catching that before (expected behaviour), and not fixing it can lead to data loss.

If we were changing an expected behaviour then I'd consider it a breaking change.

@dnlopes
Copy link

dnlopes commented Jun 7, 2022

I was wondering if this is not a breaking change. If EMF fails silently, we might have customers sending more than the allowed dimensions in theirs runtime (but failing silently). As soon as they bump the powertools version, their code will start to blowup at runtime instead of just not producing metrics dimensions.

My personal take is that this falls under a bug - we should've been catching that before (expected behaviour), and not fixing it can lead to data loss.

If we were changing an expected behaviour then I'd consider it a breaking change.

I don't think they are mutually exclusive, but I'm not familiar with the vision you have for this project regarding these kind of changes. We might have different takes on how a breaking change is defined, but, in any case, that would be a whole new discussion that does not belong here.

The PR changes look good. ✅

@heitorlessa
Copy link
Contributor Author

absolutely @dnlopes, I'd go as far as suggesting it'd be great to jump on a call to discuss this. While we're making strides in creating a maintainers playbook and improve our definitions, there's so much more that we could do.

Gonna proceed to releasing it now as a patch.

@heitorlessa heitorlessa changed the title fix(metrics): ensure service uses add_dimension fix(metrics): raise SchemaValidationError for >8 metric dimensions Jun 7, 2022
@heitorlessa heitorlessa merged commit f4fdcba into aws-powertools:develop Jun 7, 2022
@heitorlessa heitorlessa deleted the fix/metrics-dimension-limit branch June 7, 2022 14:41
@michaelbrewer
Copy link
Contributor

Breaking changes for sure. Needed. But still a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants